package schoolbolg_gh326.Activity;

import java.util.List;

import schoolbolg_gh326.Adapter.BlogAdapter;
import schoolbolg_gh326.Adapter.BlogDBAdapter;
import schoolbolg_gh326.Bean.BlogBean;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.example.schoolbolg_gh326.R;


public  class FollowActivity extends Activity implements OnClickListener{
	ListView listView;
	Button button_add, button_deleteall;
	Context context;
	BlogAdapter adapter;
	BlogDBAdapter dbAdapter;
	List<BlogBean> list;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_follow);
		context = FollowActivity.this;
		initView();
		dbAdapter=BlogDBAdapter.getInstance(context);
		
		list=dbAdapter.queryAll();
		adapter=new BlogAdapter(context, list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				BlogBean blogBean=list.get(arg2);
				Intent intent=new Intent(context, EditBlogActivity.class);
				intent.putExtra("_id", blogBean.get_id());
				intent.putExtra("name", blogBean.getName());
				intent.putExtra("tel", blogBean.getTel());
				startActivity(intent);
			}
		});
	}
	void initView() {
		button_add = (Button) findViewById(R.id.button_blog_add);
		button_deleteall = (Button) findViewById(R.id.button_blog_deleteall);
		
		button_add.setOnClickListener(this);
	button_deleteall.setOnClickListener(this);
		
		listView=(ListView)findViewById(R.id.listView_blog);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.button_blog_add:
			Intent intent1=new Intent(context, AddBlogActivity.class);
			startActivity(intent1);
			break;

		case R.id.button_blog_deleteall:
		
			break;
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		list=dbAdapter.queryAll();
		adapter.setList(list);
		adapter.notifyDataSetChanged();
		
	}
	
	/*@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		dbAdapter.closeDB();
	}*/
}
